
function openLjt() {
  var lajitongModule =  document.getElementById("lajitong-module");
  if (lajitongModule.classList.contains('choose-module-lajitong')) {

    // initLajitongDetailData(n)
  }else {
    // initLajitongDetailData(n)
    chooseModule('choose-module-lajitong','lajitong','告警分析 >>')
    $("#lajitong").show();
  }

}


$(function(){
  function initAllLjtData(data) {
    var allLjtData = data.wulianwang[2].ljtAllInfo;

   var  alertLjtData = function(n) {
     $(".lajitong-module .lajitong-btn").click(function(event){
        var target = $(this).attr('target');
        var thisLjtData = allLjtData[target];
        var lajitongDetailChart = echarts.init(document.getElementById('lajitong-detail-chart'));
        var lajitongDetailOption = {
          "tooltip": {
            "position": "top"
          },
          backgroundColor: 'rgba(35,237,239,0.1)',
          color: ['#faba25'],
          "title": [{
            "textBaseline": "middle",
            "top": "7.142857142857143%",
            "text": "本日开门次数",
            textStyle: {
              color: "white",
              fontSize: 18,
              fontWeight: 300
            }
          }],
          "singleAxis": [{
            "left": 70,
            "type": "category",
            "boundaryGap": false,
            top: 50,
            bottom: 50,
            "data": ['0','1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23'],
            "axisLabel": {
              "interval": 2
            },
            axisLine: {
              lineStyle: {
                color: 'rgb(35,237,239)'
              }
            },
            axisLabel: {
              color: 'rgb(35,237,239)'
            }
          }],
          "series": [{
            "singleAxisIndex": 0,
            "coordinateSystem": "singleAxis",
            "type": "scatter",
            "data": thisLjtData.opens,
            symbolSize: function(dataItem) {
              return dataItem * 4;
            }
          }, ]
        }
        lajitongDetailChart.setOption(lajitongDetailOption);
        $("#dingwei_span").text(parseFloat(thisLjtData.localy).toFixed(3)+','+parseFloat(thisLjtData.localx).toFixed(3));
        $("#90_span").text(thisLjtData.compress90count);
        $("#dianya_span").text(thisLjtData.primarybattery + 'V');
        $("#yasuo_span").text(parseInt(thisLjtData.compress)?"异常":"正常");
        $("#tianzhuang_span").text(parseInt(thisLjtData.batterystatus)?"充电中":"未充电");
        $("#yuyin_span").text(parseInt(thisLjtData.voice)?"异常":"正常");
        $("#kaimen_span").text(parseInt(thisLjtData.open)?"异常":"正常");
        $("#70_span").text(thisLjtData.compress70count);
        $("#gundong_span").text(parseInt(thisLjtData.scroll)?"异常":"正常");
        openLjt();
     })
   }
     alertLjtData()
  }

  function initLjiData(data,id,n) {
     var allLjtData = data.wulianwang[2].ljtAllInfo;
     var thisljtData = allLjtData[n];
     var thisParent = $("#" + id ).parents('.lajitong-box');
     thisParent.find('.dianya-span').text(thisljtData.primarybattery + 'V');
     thisParent.find('.jingdu-span').text(parseFloat(thisljtData.localx).toFixed(3));
     thisParent.find('.weidu-span').text(parseFloat(thisljtData.localy).toFixed(3));
     var lajitong001Chart = echarts.init(document.getElementById(id));
     var normalColor = ['rgba(31,139,215,0.5)','#1f8bd7','rgba(31,139,215,0.2)'];
     var redColor = ['rgba(35,237,239,0.1)','rgb(255, 51, 75)','rgba(255, 51, 75,0.2)'];
     var yellowColor = ['rgba(250, 186, 37,0.5)','rgb(250, 186, 37)','rgba(250, 186, 37,0.2)'];
     var thisColor;
     var thisLjtCap = parseInt(thisljtData.capacity.split('%')[0]);
     if(thisLjtCap<70) {
       thisColor = normalColor;
     }else if (thisLjtCap<90 ) {
       thisColor = yellowColor
     }else {
       thisColor = redColor
     }
     var lajitong001Option = {
       series: [
         {
         type: 'liquidFill',
         data: [thisLjtCap*0.75*0.01],
         color: [thisColor[0]],
         radius: '100%',
         outline: {
           show: false
         },
         backgroundStyle: {
           borderColor: thisColor[1],
           borderWidth: 1,
           shadowColor: 'rgba(0, 0, 0, 0.4)',
           shadowBlur: 20,
           color: thisColor[2]
         },
         shape: 'path://M124.000,27.383 L4.000,27.383 C2.343,27.383 1.000,26.040 1.000,24.383 L1.000,13.362 C1.000,11.705 2.343,10.361 4.000,10.361 L28.622,10.361 L35.905,1.000 L92.094,1.000 L99.378,10.361 L124.000,10.361 C125.657,10.361 127.000,11.705 127.000,13.362 L127.000,24.383 C127.000,26.040 125.657,27.383 124.000,27.383 ZM117.635,139.000 C117.635,151.150 107.785,161.000 95.635,161.000 L32.365,161.000 C20.214,161.000 10.365,151.150 10.365,139.000 L10.365,36.745 L117.635,36.745 L117.635,139.000 Z',
         label: {
           normal: {
             position: ['50%', '50%'],
             formatter: function() {
               return thisLjtCap + '%';
             },
             fontSize: 12,
             color: '#7c7c7c',
             textStyle: {
               fontSize: 12,
               color: '#7c7c7c',
               fontWeight: 300,
             }
           }
         }
       }]
     }

     lajitong001Chart.setOption(lajitong001Option);

  }

  function initLajitongDetailData(data) {

    var lajitongDetailChart = echarts.init(document.getElementById('lajitong-detail-chart'));

    var lajitongDetailOption = {
      "tooltip": {
        "position": "top"
      },
      backgroundColor: 'rgba(35,237,239,0.1)',
      color: ['#faba25'],
      "title": [{
        "textBaseline": "middle",
        "top": "7.142857142857143%",
        "text": "本周开门次数",
        textStyle: {
          color: "white",
          fontSize: 18,
          fontWeight: 300
        }
      }],
      "singleAxis": [{
        "left": 70,
        "type": "category",
        "boundaryGap": false,
        top: 50,
        bottom: 50,
        "data": ["09-01","09-02","09-03","09-04","09-05","09-06","09-07"],
        "axisLabel": {
          "interval": 2
        },
        axisLine: {
          lineStyle: {
            color: 'rgb(35,237,239)'
          }
        },
        axisLabel: {
          color: 'rgb(35,237,239)'
        }
      }],
      "series": [{
        "singleAxisIndex": 0,
        "coordinateSystem": "singleAxis",
        "type": "scatter",
        "data": [2,4,6,8,10,15,20],
        symbolSize: function(dataItem) {
          return dataItem * 4;
        }
      }, ]
    }

    lajitongDetailChart.setOption(lajitongDetailOption);

    console.log(data);

  }
  function initLudengData(data) {
    // var ludengData = data.wulianwang[3].ldAllInfo.energy;
    // var time = [];
    // var energy = [];
    // for( k in ludengData) {
    //      time.push(k);
    //      energy.push(ludengData[k]);
    // }
    // console.log(time);
    // console.log(energy);
      var thisData = data.wulianwang[3].ldAllInfo;
      console.log(thisData);
      $('.thisyear').text(Math.round(thisData.thisyear));
      $('.thismonth').text(Math.round(thisData.thismonth));
    var ludengChart = echarts.init(document.getElementById('ludeng-chart'));

    var monthData = function() {
      var data = [];
      for (var i = 1; i < 13; i++) {
        data.push(i + "月份");
      }
      return data;
    }();

    var ludengOption = {
      color: ["#64aee3"],
      "tooltip": {
        "trigger": "axis",
        "axisPointer": {
          "type": "shadow",
          textStyle: {
            color: "#fff"
          }
        },
      },
      "grid": {
        "borderWidth": 0,
        "top": 10,
        "bottom": 45,
        right: 10,
        left: 40,
        textStyle: {
          color: "#23edef"
        }
      },
      "calculable": true,
      "xAxis": [{
        "type": "category",
        "axisLine": {
          lineStyle: {
            color: '#64aee3',
            fontSize: 12
          }
        },
        "splitLine": {
          "show": false
        },
        "axisTick": {
          "show": false
        },
        "splitArea": {
          "show": false
        },
        axisLabel: {
          textStyle: {
            color: '#000',
            fontSize: 12
          }
        },
        "data": thisData.month,
      }],
      "yAxis": [{
        "type": "value",
        "splitLine": {
          "show": false
        },
        "axisLine": {
          lineStyle: {
            color: '#64aee3',
            fontSize: 12
          }
        },
        "axisTick": {
          "show": false
        },
        axisLabel: {
          textStyle: {
            color: '#64aee3',
            fontSize: 12
          }
        },
        splitLine: {
          lineStyle: {
            color: ['#64aee3'],
          }
        },
        // splitArea: {
        //   show: true,
        //   areaStyle: {
        //     color: ['rgba(35,237,239,0.1)']
        //   }
        // }

      }],
      "dataZoom": [{
        "show": true,
        "height": 20,
        "xAxisIndex": [
          0
        ],
        bottom: 0,
        "start": 30,
        "end": 100,
        handleIcon: 'path://M306.1,413c0,2.2-1.8,4-4,4h-59.8c-2.2,0-4-1.8-4-4V200.8c0-2.2,1.8-4,4-4h59.8c2.2,0,4,1.8,4,4V413z',
        handleSize: '110%',
        fillerColor: 'rgba(100,174,227,0.4)',
        handleStyle: {
          color: "#64aee3",

        },
        textStyle: {
          color: "#64aee3"
        },
        borderColor: "#64aee3"
      }, {
        "type": "inside",
        "show": true,
        "height": 15,
        "start": 1,
        "end": 35
      }],
      "series": [{
        "name": "总数",
        "type": "line",
        "stack": "总量",
        symbolSize: 14,
        "data": thisData.energy
      }, ]
    }

    ludengChart.setOption(ludengOption);
  }
  function initenvAllInfoData(data)  {
    var thisData = data.wulianwang[5].envAllInfo.envAllInfo.envInfo;
    $("#wendu-data").text(thisData.温度);
    $("#shidu-data").text(thisData.湿度);
    $("#qiya-data").text(thisData.气压);
    $("#pm-data").text(thisData["PM2.5"]);
    $("#zhaodao-data").text(thisData.照度);
    $("#fengsu-data").text(thisData.风速);
    $("#fengxiang-data").text(thisData.风向);

  }
  function initAll(data) {
    initLudengData(data);
    // initLajitongDetailData(data);
    initLjiData(data,'lajitong001',0);
    initLjiData(data,'lajitong002',1);
    initLjiData(data,'lajitong003',2);
    initLjiData(data,'lajitong004',3);
    initenvAllInfoData(data);
    initAllLjtData(data);
  }
  $.ajax({
    type: "get",
    // url: "src/js/wulianwang.json",
    url : baseUrl+"/wlw/indexAll",
    dataType: "json",
    cache: false,
    data: {},
    success: function(data) {
      var allData = data;
        initAll(data);
    }
  });
})
